$(document).ready(function(){
		scrollComment();
	});

	//评论滚动
	var scrollComment = function(){
		var comment = $(".comment");
		var box = $(".comment-inner");
		var boxClone = box.clone(false);
		comment.append(boxClone);

		setInterval(function(){
			if (boxClone[0].offsetHeight - comment[0].scrollTop <= 0) {
	            comment[0].scrollTop -= box[0].offsetHeight;
	        } else {
	            comment[0].scrollTop++;
	        }
		},40)
	}

	var loadImage = function(){
		var src = $(".banner-item img").attr("src");
		var img = new Image();
		var flag = true;
		img.onload = function(){
			loadImages();
		}
		img.onerror = function(){
			loadImages();
		}
		setTimeout(function(){
			loadImages();
		},1500);
		var loadImages = function(){
			if(flag){
				flag = false;
				$(".lazy-img").each(function(){
					var $ele = $(this);
					$ele.attr({'src':$ele.attr("data-src")});
				});
			}
		}
		img.src = src;
	}

// 倒计时
var max=2102;
var timer=null;

function setCookie(){
	var enterdate = new Date();
	var exp  = new Date();
	exp.setTime(exp.getTime() + max*1000);  //cookie过期时间为当前时间+max秒
	document.cookie = "starttime" + "="+ escape(enterdate) + ";expires=" + exp.toGMTString();  //保存进入时间
	document.cookie = "endtime" + "="+ escape(exp) + ";exp=" + exp.toGMTString();  //保存结束时间
}

function getCookie(name){
	var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
	if(arr=document.cookie.match(reg)){
		return unescape(arr[2]);
	}else{
		return null;
	}
}

function daojishi(id){
	var date1=new Date();  //当前时间
	var date2=new Date(getCookie("endtime"));    //结束时间
	var remain=parseInt((date2.getTime()-date1.getTime())/1000);  //剩余时间
	var hour = parseInt(remain/3600) < 10 ? "0"+parseInt(remain/3600) : parseInt(remain/3600);
	var minute = parseInt(remain/60) < 10 ? "0"+parseInt(remain/60) : parseInt(remain/60);
	var second = parseInt(remain%60) < 10 ? "0"+parseInt(remain%60) : parseInt(remain%60);
	var cc = document.getElementById(id);
	cc.innerHTML = "<span>"+hour+"</span>"+"小时"+"<span>"+minute+"</span>"+"分"+"<span>"+second+"</span>"+"秒";
	if(remain == 0){
		clearInterval(timer);
	}
	if(remain > max){
		setCookie();
	}
}

$(document).ready(function(){
	if(!getCookie('starttime')){
		setCookie();
		timer = setInterval(function(){
			daojishi('remainTime_1');
			daojishi('remainTime_2');
		},1000);
	}
	else{
		timer = setInterval(function(){
			daojishi('remainTime_1');
			daojishi('remainTime_2');
		},1000);
	}
})
